<?php

namespace app\logic;

use app\models\DemoModel;
use yii\base\ErrorException;

class DemoLogic extends BaseLogic
{
    public $tokenData = array();
    private $demoModel = null;

    public function __construct($tokenData = array())
    {
        parent::__construct();

        // TOKEN信息
        $this->tokenData = $tokenData;

        if ($this->demoModel == null) {
            $this->demoModel = new DemoModel();
        }
    }

    // 用户登录
    public function login($post)
    {
        $data = array();
        $data['account'] = isset($post['account']) ? trim($post['account']) : '';
        $data['password'] = isset($post['password']) ? trim($post['password']) : '';

        if (empty($data['account']) || empty($data['password'])) {
            throw new ErrorException(null, 4000);
        }
        // DB查询
        $loginRes = $this->demoModel->login($data);
        if (!isset($loginRes['password']) || $loginRes['password'] != $data['password']) {
            throw new ErrorException(null, 4001);
        }
        return $loginRes;
    }
}
